﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="CustomerMasterForm.aspx.cs"
    Inherits="PSS.WebSite.SetManage.BasicData.CustomerMasterForm" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>客户管理</title>
    <script src="../../lib/boot.js" type="text/javascript"></script>
</head>
<body>
    <div class="mini-toolbar" style="padding: 2px; border-bottom: 0;">
        <table style="width: 100%;">
            <tr>
                <td style="width: 100%;">
                    客户类别：<input id="CCategoryId" class="mini-combobox" style="width: 120px;" valuefield="CCategoryId"
                        textfield="CCategoryName" />
                    客户编号：<input id="CustomerCode" class="mini-textbox" emptytext="请输入客户编号" style="width: 120px;"
                        onenter="onKeyEnter" />
                    客户名称：<input id="CustomerName" class="mini-textbox" emptytext="请输入客户名称" style="width: 120px;"
                        onenter="onKeyEnter" />
                    <a class="mini-button" iconcls="icon-search" onclick="search()">查 询</a> <a class="mini-button"
                        iconcls="icon-reset" onclick="reset()">重 置</a>
                </td>
            </tr>
        </table>
    </div>
    <div class="mini-toolbar" style="padding: 2px; border-bottom: 0;">
        <table style="width: 100%;">
            <tr>
                <td style="width: 100%;">
                    <a class="mini-button" id="add" iconcls="icon-add" onclick="add();" plain="true">添加</a>
                    <a class="mini-button" id="edit" iconcls="icon-edit" onclick="edit()" plain="true">编辑</a>
                    <a class="mini-button" iconcls="icon-remove" id="remove" onclick="remove()" plain="true">
                        删除</a> <span class="separator"></span><a class="mini-button" onclick="close()" iconcls="icon-close"
                            plain="true">关闭</a>
                </td>
            </tr>
        </table>
    </div>
    <!--撑满页面-->
    <div class="mini-fit">
        <div id="grid1" class="mini-datagrid" style="width: 100%; height: 100%;" idfield="CustomerId"
            sizelist="[10,20,50,100]" pagesize="20">
            <div property="columns">
                <div type="indexcolumn" width="20">
                </div>
                <div field="CCategoryName" width="120" headeralign="center" allowsort="true">
                    客户类别
                </div>
                <div field="CustomerCode" width="120" headeralign="center" allowsort="true">
                    客户编号
                </div>
                <div field="CustomerName" width="120" headeralign="center" allowsort="true">
                    客户名称
                </div>
                <div field="Linkman" width="120" headeralign="center" allowsort="true">
                    首要联系人
                </div>
                <div field="MobilePhone" width="120" headeralign="center" allowsort="true">
                    手机
                </div>
                <div field="SpecialPlane" width="120" headeralign="center" allowsort="true">
                    座机
                </div>
                <div field="QqMsn" width="120" headeralign="center" allowsort="true">
                    QQ/MSN
                </div>
                <div field="Price" width="150" headeralign="center" allowsort="false">
                    期初往来余额
                </div>
            </div>
        </div>
    </div>
    <script type="text/javascript">
        mini.parse();
        var CCategory = mini.get("CCategoryId");
        CCategory.setUrl("../../Service/SetManageHandler.ashx?action=GetCustomerCategoryListByCombobox");
        var grid = mini.get("grid1");
        grid.setUrl("../../Service/SetManageHandler.ashx?action=GetCustomerList");
        grid.load();
        function search(e) {
            var CCategoryId = mini.get("CCategoryId").getValue();
            var CustomerCode = mini.get("CustomerCode").getValue();
            var CustomerName = mini.get("CustomerName").getValue();
            grid.load({ CCategoryId: CCategoryId, CustomerCode: CustomerCode, CustomerName: CustomerName });
        }
        function onKeyEnter(e) {
            search();
        }
        function reset(e) {
            mini.get("CCategoryId").setValue("");
            mini.get("CustomerCode").setValue("");
            mini.get("CustomerName").setValue("");
        }
        function add() {
            mini.open({
                url: "SetManage/BasicData/CustomerInfoForm.aspx",
                title: "添加客户", width: 800, height: 580,
                onload: function () {
                    var iframe = this.getIFrameEl();
                    var data = { action: "new" };
                    iframe.contentWindow.SetData(data);
                },
                ondestroy: function (action) {
                    grid.reload();
                }

            });
        }
        function edit() {
            var row = grid.getSelected();
            if (row) {
                mini.open({
                    url: "SetManage/BasicData/CustomerInfoForm.aspx",
                    title: "编辑客户", width: 800, height: 580,
                    onload: function () {
                        var iframe = this.getIFrameEl();
                        var data = { action: "edit", CustomerId: row.CustomerId };
                        iframe.contentWindow.SetData(data);

                    },
                    ondestroy: function (action) {
                        grid.reload();
                    }
                });

            } else {
                mini.alert("请选中一条记录!");
            }
        }
        function remove() {
            var row = grid.getSelected();
            if (row) {
                mini.confirm("您确定要删除:" + row.CustomerName + "？", "确定？",
                        function (action) {
                            if (action == "ok") {
                                $.ajax({
                                    url: "../../service/SetManageHandler.ashx?action=RemoveCustomer&CustomerId=" + row.CustomerId,
                                    success: function (text) {
                                        grid.reload();
                                    },
                                    error: function (jqXHR, textStatus, errorThrown) {
                                        alert(jqXHR.responseText);
                                    }
                                });
                            } else {
                                return false;
                            }
                        });

            } else {
                mini.alert("请选中一条记录!");
            }
        }
        function CloseWindow(action) {
            if (window.CloseOwnerWindow) return window.CloseOwnerWindow(action);
            else window.close();
        }
        function close() {
            CloseWindow("close");
        }
    </script>
</body>
</html>
